<?php

namespace App\Console\Commands;

use App\Models\User\User;
use Illuminate\Console\Command;
use App\Models\Agent\RatioLog;
use Illuminate\Support\Facades\DB;

class SetRatio extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:zongdai-ratio';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {   
        $rel = RatioLog::where('is_set', 0)->get();
        foreach($rel as $val) {
            $ratio = RatioLog::find($val->id);
            $ratio->is_set = 1;
            $ratio->save();

            $user = User::find($val->user_id);
            $user->zong_ratio = $val->ratio;
            $user->save();
        }
    }
}
